/*
 * $Id: memory.h 50 2009-02-10 05:48:05Z hyunghwan.chung $
 *
   Copyright 2005-2009 Chung, Hyung-Hwan.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an  BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

#ifndef _XP_BAS_MEMORY_H_
#define _XP_BAS_MEMORY_H_

#include <xp/types.h>
#include <xp/macros.h>

#include <stdlib.h> 
#define xp_malloc  malloc
#define xp_free    free
#define xp_realloc realloc
#define xp_calloc  calloc    

#ifdef __cplusplus
extern "C" {
#endif

void* xp_memcpy_i  (void* dst, const void* src, xp_size_t n);
void* xp_memmove_i (void* dst, const void* src, xp_size_t n);
void* xp_memset_i  (void* dst, int byte, xp_size_t n);
int   xp_memcmp_i  (const void* s1, const void* s2, xp_size_t n);
void* xp_memchr_i  (const void* s, int byte, xp_size_t n);
void* xp_memrchr_i (const void* s, int byte, xp_size_t n);
void* xp_memmem (
	const void* haystack, xp_size_t hsz, const void* needle, xp_size_t nsz);
xp_size_t xp_swab (void* dst, const void* src, xp_size_t n);

#ifdef __cplusplus
}
#endif

/*
#if defined(XP_USE_STOCK_FUNCTIONS)
*/
	#include <string.h>

	#define xp_memset(dst,fill,len)  memset(dst,fill,len)
	#define xp_memcpy(dst,src,len)   memcpy(dst,src,len)
	#define xp_memmove(dst,src,len)  memmove(dst,src,len)
	#define xp_memcmp(src1,src2,len) memcmp(src1,src2,len)
	#define xp_memzero(dst,len)      memset(dst,0,len)
	#define xp_memchr(s,byte,n)      memchr(s,byte,n)


	#define XP_MEMSET(dst,fill,len)  memset(dst,fill,len)
	#define XP_MEMCPY(dst,src,len)   memcpy(dst,src,len)
	#define XP_MEMMOVE(dst,src,len)  memmove(dst,src,len)
	#define XP_MEMCMP(src1,src2,len) memcmp(src1,src2,len)
	#define XP_MEMZERO(dst,len)      memset(dst,0,len)
	#define XP_MEMCHR(s,byte,n)      memchr(s,byte,n)
/*
#else
	#define xp_memcpy   xp_memcpy_i
	#define xp_memmove  xp_memmove_i
	#define xp_memset   xp_memset_i
	#define xp_memcmp   xp_memcmp_i
	#define xp_memchr   xp_memchr_i
#endif
*/

#define xp_memrchr xp_memrchr_i
#define XP_MEMRCHR xp_memrchr_i

#endif
